package cf;

import java.util.*;

public class RemainNumbersInStack {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] nums = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        HashMap<Integer,Integer> hashMap = new HashMap<>();
        int[] prefixSum = new int[nums.length];
        Stack<Integer> stack = new Stack<>();
//        int item
        prefixSum[0] = nums[0];
        hashMap.put(nums[0],0);
        stack.push(nums[0]);

        for (int i = 1; i < nums.length; i++) {
            if (prefixSum[stack.size() - 1] < nums[i]) {
                prefixSum[stack.size()] = prefixSum[stack.size() - 1] + nums[i];
                stack.push(nums[i]); // 元素入栈
                hashMap.put(prefixSum[stack.size() - 1],stack.size() - 1);
            }else {
                if (prefixSum[stack.size() - 1] == nums[i]) {
                    stack.clear();
                    stack.push(nums[i] + nums[i]);
                    prefixSum[stack.size() - 1] = nums[i] + nums[i];
                    hashMap.clear();
                    hashMap.put((nums[i] + nums[i]),0);
                } else if(hashMap.containsKey(prefixSum[stack.size() - 1] - nums[i])){
                    int itemCnt = stack.size() - 1 - hashMap.get(prefixSum[stack.size() - 1] - nums[i]);
                    for (int j = 0; j <itemCnt ; j++) {
                        hashMap.remove(prefixSum[stack.size() - 1 - j]);
                        prefixSum[stack.size()-1-j] = 0;
                        stack.pop();
                    }
                    stack.push(nums[i] + nums[i]);
                    prefixSum[stack.size() - 1] = nums[i] + nums[i];
                    hashMap.put(nums[i] + nums[i],stack.size()-1);
                } else {
                    prefixSum[stack.size()] = prefixSum[stack.size() - 1] + nums[i];
                    stack.push(nums[i]); // 元素入栈
                    hashMap.put(prefixSum[stack.size() - 1],stack.size() - 1);
                }
            }

        }
        StringJoiner stringJoiner = new StringJoiner(" ");
        while (!stack.isEmpty()) {
            stringJoiner.add(stack.pop() + "");
        }
        System.out.println(stringJoiner.toString());
    }

}
